<!-- 课程管理(模块) => 课程列表(菜单) => 台账操作列(学生列表按钮) => 点开 => 新窗口台账操作列(签到记录) => 点开后展示此组件 -->
<template>
  <Dialog :title="t('signStudentLog.index.title')" v-model="dialogVisible" width="700">
    <!-- 列表 -->
    <ContentWrap>
      <vxe-table
        id="iCourseSignStudentLogPersonal-table"
        v-loading="loading"
        :data="list"
        stripe
        :custom-config="vxeTableConfig"
        :column-config="{ resizable: true }"
        :size="vxeTableSize"
      >
        <vxe-column :title="t('common.index')" type="seq" field="seq" width="60" align="center" />
        <vxe-column
          :title="t('signStudentLog.fields.studentName')"
          field="studentName"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
        >
          <template #default>
            <span>{{ student.studentName }}</span>
          </template>
        </vxe-column>
        <vxe-column
          :title="t('signStudentLog.fields.startDate')"
          field="startDate"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
          :formatter="vxeDateFormatter"
        />
        <vxe-column
          :title="t('signStudentLog.fields.endDate')"
          field="endDate"
          align="center"
          show-header-overflow
          show-overflow
          min-width="100"
          :formatter="vxeDateFormatter"
        />
      </vxe-table>
      <!-- 分页 -->
      <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </ContentWrap>
  </Dialog>
</template>

<script setup lang="ts">
import { SignStudentLogApi, SignStudentLogVO } from '@/api/course/signstudentlog'
import type { VxeTablePropTypes } from 'vxe-table'
import { useAppStore } from '@/store/modules/app'
import { CourseStudentListRespVO } from '@/api/course/student'
import { vxeDateFormatter } from '@/utils/formatTime'

/** 课程签到学生记录 列表 */
defineOptions({ name: 'CourseStudentPersonalSignLog' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const dialogVisible = ref(false)

const loading = ref(true) // 列表的加载中
const list = ref<SignStudentLogVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  courseId: undefined,
  accountId: undefined
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

const vxeTableConfig: VxeTablePropTypes.CustomConfig = {
  storage: true,
  mode: 'drawer',
  checkMethod({ column }) {
    return !['seq', 'operator'].includes(column.field)
  }
}

const appStore = useAppStore()
const vxeTableSize = computed(() => appStore.getCurrentSizeVxe)

// 查询列表 根据学生ID和课程ID 查询签到记录
const getList = async () => {
  queryParams.courseId = student.value?.courseId as any
  queryParams.accountId = student.value?.accountId as any
  loading.value = true
  try {
    const data = await SignStudentLogApi.getSignStudentLogPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

// 搜索按钮操作
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

// 重置按钮操作
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

const student = ref<CourseStudentListRespVO>()
const open = (row: CourseStudentListRespVO) => {
  student.value = row
  list.value = []
  total.value = 0
  dialogVisible.value = true
  getList()
}

defineExpose({ open })
</script>
